/**
 * Created by Administrator on 2019/5/21/021.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"

class CZML_DeleteFacilityByID {
  constructor(viewer, id) {
    this._viewer = viewer
    this.id = id
    this.CZML_DeleteFacilityByID()
  }

  CZML_DeleteFacilityByID() {
    const id = this.id
    // 查询该id相关的所有元素
    const MapNodes = CZML_GENERALTOOLS_CLASS.CzmlList.map(function (node) {
      return node.data().id.includes(id)
    })
    // 循环删除所有满足条件的节点
    for (let i = 0; i < MapNodes.length; i++) {
      if (MapNodes[i]._data.id.includes("-to-show")) {
        const rockId = MapNodes[i]._data.id.split("-to-show")[0]
        // 对idOther进行循环
        const FindNode = CZML_GENERALTOOLS_CLASS.CzmlList.find(function (node) {
          return node.data().id === rockId
        })
        const CurPathwidth = FindNode.data().path.width
        const CurPosition = FindNode.data().position
        // 添加对象
        const ShowOrbitData = {
          id: rockId + "back",
          availability: FindNode.data().availability,
          path: {
            show: true,
            width: CurPathwidth, // 轨道宽度
            material: FindNode.data().path.material,
            resolution: 120
          },
          position: CurPosition
        }
        CZML_GENERALTOOLS_CLASS.CzmlList.push(ShowOrbitData)
      }
      CZML_GENERALTOOLS_CLASS.CzmlList.remove(MapNodes[i])
    }
    if (MapNodes.length > 0) {
      // 上图
      CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
    }
  }
}

export default CZML_DeleteFacilityByID
